* Split it into 7 parts and drop the parts into a "struct hrec".
* Return a pointer to the character following the newline.
*/
#define NEXT_BAR(here) do { while (isspace(*line)) line++; hr->here = line; while ((c = *line++) && c != '|') ; if (!c) return(rtn); *(line - 1) = '\0'; } while (0)
static char *
fill_hrec (line, hr)
char *line;
struct hrec *hr;
{
char *cp, *rtn;
int c;
int off;
static int idx = 0;
bzero ((char *) hr, sizeof (*hr));
while (isspace (*line))
line++;
if (!(rtn = index (line, '\n')))
return ("");
*rtn++ = '\0';
hr->type = line++;
(void) sscanf (line, "%x", &hr->date);
while (*line && index ("0123456789abcdefABCDEF", *line))
line++;
if (*line == '\0')
return (rtn);
line++;
NEXT_BAR (user);
NEXT_BAR (dir);
if ((cp = rindex (hr->dir, '*')) != NULL)
{
*cp++ = '\0';
(void) sscanf (cp, "%x", &off);
hr->end = line + off;
}
else
hr->end = line - 1; /* A handy pointer to '\0' */
NEXT_BAR (repos);
NEXT_BAR (rev);
hr->idx = idx++;
if (index ("FOT", *(hr->type)))
hr->mod = line;
NEXT_BAR (file); /* This returns ptr to next line or final '\0' */
return (rtn); /* If it falls through, go on to next record */
}
/* read_hrecs's job is to read the history file and fill in all the "hrec"
* (history record) array elements with the ones we need to print.
*
* Logic:
* - Read the whole history file into a single buffer.
* - Walk through the buffer, parsing lines out of the buffer.
* 1. Split line into pointer and integer fields in the "next" hrec.
* 2. Apply tests to the hrec to see if it is wanted.
* 3. If it *is* wanted, bump the hrec pointer down by one.
*/
static void
read_hrecs (fname)
char *fname;
{
char *cp, *cp2;
int i, fd;
struct hrec *hr;
struct stat st_buf;
if ((fd = open (fname, O_RDONLY)) < 0)
error (1, errno, "cannot open history file: %s", fname);
if (fstat (fd, &st_buf) < 0)
error (1, errno, "can't stat history file");
/* Exactly enough space for lines data */
if (!(i = st_buf.st_size))
error (1, 0, "history file is empty");
histdata = cp = xmalloc (i + 2);
histsize = i;
if (read (fd, cp, i) != i)
error (1, errno, "cannot read log file");
(void) close (fd);
if (*(cp + i - 1) != '\n')
{
*(cp + i) = '\n'; /* Make sure last line ends in '\n' */